#include <iostream>
#include <algorithm>

struct data
{
	int id;
	int val;
};

bool cmp(data a,data b)
{
	if(a.val>b.val) return true;
	else if(a.val==b.val){
		return a.id>b.id;
	}
	else return false;
}
bool cmp1(data a,data b)
{
	return a.id<b.id;
}

using namespace std;
int main()
{
	data a[101];
	string n;
	int t,m;
	while(cin>>t){
		while(t--){
			cin>>n>>m;
			for(int i=0;i<n.length();i++){
				a[i].id=i;
				a[i].val=(int)(n[i]-'0');
			}
		sort(a,a+n.length(),cmp);
		sort(a,a+n.length()-m,cmp1);
		for(int j=0;j<n.length()-m;j++){
			cout<<a[j].val;
		}
		cout<<endl;
		}
	}
	
	
}
